<?php


namespace App\HttpController;


use App\Service\Baiyou\PatientInfusionQueueService;
use EasySwoole\Http\AbstractInterface\Controller;

class Queue extends Controller
{
    private $msgData = [
        'code' => 200,
        'msg' => 'ok',
    ];

    /**
     * 排队
     */
    function create()
    {
        $post = $this->request()->getParsedBody();
        $projectId = $post['project_id'] ?? 0;

        // 通知大屏刷新列表
        $service = new PatientInfusionQueueService();
        $service->sendScreenNoticeList($projectId);
        // 通知白友刷新列表
        $service->sendByQueueNoticeList($projectId);

        $this->response()->withHeader('Content-Type', 'application/json;charset=utf-8');
        $this->response()->write(json_encode($this->msgData));
    }

    /**
     * 叫号
     */
    function call()
    {
        $post = $this->request()->getParsedBody();
        // 队列ID
        $projectId = $post['project_id'] ?? 0;
        $id = $post['id'] ?? 0;

        // 通知大屏排队成功
        $service = new PatientInfusionQueueService();
        $service->sendScreenCall($projectId, $id);
        // 通知大屏刷新列表
        $service->sendScreenNoticeList($projectId);
        // 通知白友刷新列表
        $service->sendByQueueNoticeList($projectId);

        $this->response()->withHeader('Content-Type', 'application/json;charset=utf-8');
        $this->response()->write(json_encode($this->msgData));
    }

    /**
     * 输液
     */
    function infusion()
    {
        $post = $this->request()->getParsedBody();
        // 队列ID
        $projectId = $post['project_id'] ?? 0;
        $id = $post['id'] ?? 0;
        $type = $post['type'] ?? 1;
        // 通知大屏刷新列表
        $service = new PatientInfusionQueueService();
        $service->sendScreenNoticeList($projectId);
        // 通知大屏完成输液
        $service->sendScreenInfusionNoticeList($projectId, $id, $type);
        // 通知白友刷新列表
        $service->sendByQueueNoticeList($projectId);
        // 通知白友刷新患者
        $service->sendByPatientNoticeList($projectId);

        $this->response()->withHeader('Content-Type', 'application/json;charset=utf-8');
        $this->response()->write(json_encode($this->msgData));
    }
}